<?php
namespace api\modules\v1\controllers;

use api\modules\v1\models\user\UserAccount;
use api\modules\v1\models\userFund\UserMoneyLog;
use yii\filters\auth\HttpHeaderAuth;
use yii\helpers\ArrayHelper;
use Yii;
use yii\rest\Serializer;

/**
 * Default controller for the `v1` module
 */
class UserFundController extends DefaultController
{

    public $modelClass = 'api\modules\v1\models\userFund\UserMoneyLog';

    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'authenticator' => [
                'class' => HttpHeaderAuth::className(),    //head头部验证
                'header' => 'access-token',
                'optional' => [                     //需要过滤掉不用token参数的方法
                    'log'
                ]
            ]
        ]);
    }

    /* ====================== 个人账务管理 ========================= */
    # 帐变类型
    public function actionLog() {
        if (Yii::$app->request->isGet) {
            return (new UserMoneyLog())->getMoneyTypeMap();
        }

        // 帐变记录
        if (Yii::$app->request->isPost) {
            return (new UserMoneyLog())->getList();
        }
    }


    // 修改钱包开关
    public function actionMoneySwitch() {
        if (Yii::$app->request->isPost) {
            $model = new UserAccount();
            $model->setScenario('moneySwitch');
            if ($model->load(Yii::$app->request->post(), '')) {
                return $model->moneySwitch();
            }
        }
    }
}
